﻿using Nemerle;
using Nemerle.Collections;
using Nemerle.Text;
using Nemerle.Utility;
using Nemerle.Assertions;

using System;
using System.Collections.Generic;
using System.Linq;
using Nemerle2.Compiler;
using Microsoft.Cci;

namespace MetadataReader.CCI
{
  /// <summary>
  /// Description of CciFieldInfo.
  /// </summary>
  class CciFieldInfo : CciMemberInfo, IFieldInfo
  {
    public this([NotNull] declType : CciTypeInfo, [NotNull] fieldDef : IFieldDefinition, index : int)
    {
      base(declType, fieldDef, index);
    }
    
    /// Can be null!
    public LiteralValue : object
    {
      get
      {
        if (IsLiteral)
          FieldDefinition.CompileTimeValue.Value
        else
          null
      }
    }

    public sealed override Type : FixedType { get { Provider.GetType(FieldDefinition.Type) } }

    public sealed override MemberKind : MemberKind { get { MemberKind.Field } }

    public FieldDefinition : IFieldDefinition { get { Definition :> IFieldDefinition } }

    public IsMutable  : bool  { get { !FieldDefinition.IsReadOnly }  }

    public IsVolatile : bool
    {
      [Memoize] get { CustomAttributes.IsCustomAttributeDefined(Constants.VolatileModifierAttributeFullName) }
    }

    public IsLiteral  : bool { get { FieldDefinition.IsCompileTimeConstant }
  }
    //GetValue() : Literal;

    public sealed override IsAbstract : bool { get { false } }

    public sealed override IsStatic : bool { get { FieldDefinition.IsStatic } }
  }
}
